﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace YJYpublicClass
{
    public partial class Frm_光源控制 : Form
    {
        public Frm_光源控制()
        {
            InitializeComponent();
        }
        ILightControl tempa;
        public Frm_光源控制(ILightControl temp)
        {
            InitializeComponent();
            tempa = temp;
        }

        private void Frm_光源控制_Load(object sender, EventArgs e)
        {
            pdv_光源参数.SelectedObject = tempa.cf;
        }

        private void btn_光源连接_Click(object sender, EventArgs e)
        {
            tempa.Connect();
        }

        private void btn_光源断开_Click(object sender, EventArgs e)
        {
            tempa.Close();
        }

        private void btn_通道打开_Click(object sender, EventArgs e)
        {
            tempa.OpenChx((int)this.nud_通道选择.Value);
        }

        private void btn_通道关闭_Click(object sender, EventArgs e)
        {
            tempa.CloseChx((int)this.nud_通道选择.Value);
        }

        private void btn_亮度设置_Click(object sender, EventArgs e)
        {
            try
            {
                int value = Convert.ToInt32(this.txt_亮度值.Text);
                tempa.SetValue((int)this.nud_通道选择.Value,value);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }         
        }

        private void btn_参数保存_Click(object sender, EventArgs e)
        {
            if (XmlHelper.SaveXML("光源.xml", 外设.LightCtrl.cf) == "")
            {
                MessageBox.Show("保存成功");
            }
            else
            {
                MessageBox.Show("保存失败");
            }
        }
    }
}
